package com.pomr.model.sys;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name="agency",uniqueConstraints = {@UniqueConstraint(columnNames={"identifier"})})
public class Agency implements Serializable{
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getCoutryName() {
		return coutryName;
	}
	public void setCoutryName(String coutryName) {
		this.coutryName = coutryName;
	}
	public String getPatientName() {
		return patientName;
	}
	public void setPatientName(String patientName) {
		this.patientName = patientName;
	}
	public String getPidentifier() {
		return pidentifier;
	}
	public void setPidentifier(String pidentifier) {
		this.pidentifier = pidentifier;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public Province getProvince() {
		return province;
	}
	public void setProvince(Province province) {
		this.province = province;
	}
	public String getProvinceName() {
		return provinceName;
	}
	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}
	public City getCity() {
		return city;
	}
	public void setCity(City city) {
		this.city = city;
	}
	public String getCityName() {
		return cityName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}
	public Integer getPatientId() {
		return patientId;
	}
	public void setPatientId(Integer patientId) {
		this.patientId = patientId;
	}
	public String getIdentifier() {
		return identifier;
	}
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getAddr() {
		return addr;
	}
	public void setAddr(String addr) {
		this.addr = addr;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public User getCreateUser() {
		return createUser;
	}
	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}
	public Coutry getCoutry() {
		return coutry;
	}
	public void setCoutry(Coutry coutry) {
		this.coutry = coutry;
	}
	public String getCreateName() {
		return createName;
	}
	public void setCreateName(String createName) {
		this.createName = createName;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")//AUTO 在mysql中需要指定使用本地策略生成主键值
	private Integer id;
	@Column(name="identifier",length=30)
	private String identifier;//机构编号
	@Column(name="name",length=50,nullable=false)
	private String name;
	@Column(name="status",length=1,columnDefinition="varchar(1) default '0'")
	private String status;//状态 1作废
	@Column(name="addr",length=150)
	private String addr;
	@Column(name="tel",length=30)
	private String tel;//机构联系电话
	@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
	@Column(name="create_time")
	private Date createTime;
	
	@ManyToOne(fetch = FetchType.LAZY)// 指定多对一关系    不维护关系 懒加载
	@JoinColumn(name="create_user")  
	private User createUser;
	@Formula("(select u.name from user u where u.id=create_user)")
	private String userName;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="province_id") 
	private Province province;//省
	@Formula("(select pr.name from province pr where pr.id=province_id)")
	private String provinceName;//省名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="city_id") 
	private City city;//市
	@Formula("(select ci.name from city ci where ci.id=city_id)")
	private String cityName;//市名
	@ManyToOne(fetch = FetchType.LAZY)// 指定多对一关系    不维护关系 懒加载
	@JoinColumn(name="coutry_id")  
	private Coutry coutry;
	@Formula("(select c.name from coutry c where c.id=coutry_id)")
	private String coutryName;//县名
	@Column(name="create_name",length=50)
	private String createName;
	@Column(name="remark",length=200)
	private String remark;//备注
	
	@Column(name="patient_id")
	private Integer patientId;//所属机构
	
	@Column(name="patient_identifier",length=50)
	private String pidentifier;//所属机构编号
	
	@Column(name="patient_name",length=50)
	private String patientName;//所属机构名称
	
	@Override
	public String toString() {
		System.out.println("id:"+id);
		System.out.println("name:"+name);
		System.out.println("addr:"+addr);
		System.out.println("coutryid:"+coutry.getId());
		System.out.println("createName:"+createName);
		System.out.println("createTime:"+createTime);
		System.out.println("createUserId:"+createUser.getId());
		
		return super.toString();
	}

}
